<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<div class="dialog-warp-ajax">
    <form action="" id="flowCopy">
        <input type="hidden" name="flowId" value="${rzFlow.id}"/>
        <table class="dggui-table-info">
            <tbody>
            <tr>
                <th><span class="required">生产事业部：</span></th>
                <td id="productOrg">
                    <select id="orgId" name="orgId" class="dggui-select">
                    </select>
                </td>
            </tr>
            <tr>
                <th><span class="required">业务类型：</span></th>
                <td>
                    <input type="hidden" name="typeCodeCopy" id="typeCodeCopyHidden" class="plug-in-code"/>
                    <div name="typeCodeCopys" id="typeCodeCopy"></div>
                </td>
            </tr>
            <tr>
                <th><span class="required">业务办理周期：</span></th>
                <td>
                    <div class="unit-warp">
                        <input type="number" class="dggui-input" id="blDate" name="blDate" max="10000" min="0" value="${rzFlow.managementCycle}">
                        <span class="unit">天</span>
                    </div>
                </td>
            </tr>
            <tr>
                <th><span class="required">工作日/自然日：</span></th>
                <td>
                    <select name="isnaturalorworkday" class="dggui-select">
                        <option value="1" <c:if test="${rzFlow.isnaturalorworkday==1}">selected</c:if>>工作日</option>
                        <option value="2" <c:if test="${rzFlow.isnaturalorworkday==2}">selected</c:if>>自然日</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th><span class="required">审核级数：</span></th>
                <td>
                    <select class="dggui-select" name="examinGrade">
                        <option value="1" <c:if test="${rzFlow.examineGrade==1}">selected</c:if>>一级</option>
                        <option value="2" <c:if test="${rzFlow.examineGrade==2}">selected</c:if>>二级</option>
                        <option value="3" <c:if test="${rzFlow.examineGrade==3}">selected</c:if>>三级</option>
                        <option value="4" <c:if test="${rzFlow.examineGrade==4}">selected</c:if>>四级</option>
                        <option value="5" <c:if test="${rzFlow.examineGrade==5}">selected</c:if>>五级</option>
                        <option value="6" <c:if test="${rzFlow.examineGrade==6}">selected</c:if>>六级</option>
                        <option value="7" <c:if test="${rzFlow.examineGrade==7}">selected</c:if>>七级</option>
                        <option value="8" <c:if test="${rzFlow.examineGrade==8}">selected</c:if>>八级</option>
                        <option value="9" <c:if test="${rzFlow.examineGrade==9}">selected</c:if>>九级</option>
                        <option value="10" <c:if test="${rzFlow.examineGrade==10}">selected</c:if>>十级</option>
                    </select>
                </td>
            </tr>
            </tbody>
        </table>
        <%--<input type="hidden" name="flowId" value="${rzFlow.id}"/>--%>
    </form>
</div>
<script>
    dggui.use(['select2','distpicker'], function (){
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;

        //初始化所属生产事业部
        syb("#orgId");
         select2.render({
             placeholder: "请选择",
             elem: $('#orgId'),
             allowClear: true,
             width: "190px"
         });
        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&&type=2&&level=2", // 请求地址
            elem: '#typeCodeCopy', // 容器Id
            placeholder: '选择业态',
            type:2,
            defaultParentCode:'BUS_YT_DK',
            /*callback:function () {
                var code = $("#typeCodeCopy .plug-in-code").val();
                initProductCode("#productCode",code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                     elem: $('#productCode'),
                    width: "190px"
                });
            }*/
        });
    });
    function flowCopy(index){
        var addressDeptId = $('[name="orgId"]').val();
        var busYtCode = $('#typeCodeCopy .plug-in-code').val();
        $("#typeCodeCopyHidden").val(busYtCode);
        var blDate = $('[name="blDate"]').val();
        var reg = /^[1-9]\d*$/;
        if (!addressDeptId) {
            dggui.dialog.tip('请选择所属事业部！',$('#productOrg'));
            return;
        }
        if (!busYtCode) {
            dggui.dialog.tip('请选择业态！',$('#typeCodeCopy'));
            return;
        }
        if(!reg.test(blDate)){
            dggui.dialog.tip('请输入正确的业务办理周期！',$('#blDate'));
            return;
        }
        if(blDate==0){
            dggui.dialog.tip('办理周期不能为零！',$('#blDate'));
            return;
        }
        if (!blDate) {
            dggui.dialog.tip('请选择业务办理周期！',$('#blDate'));
            return;
        }
        if(parseInt(blDate)>10000){
            dggui.dialog.tip('业务办理周期不能大于10000天！',$('#blDate'));
            return;
        }
        var params = $('#flowCopy').serializeArray();
        dggui.dialog.loading();
        $.ajax({
            type: 'POST',
            async: true,
            data: params,
            url: sysInfo.basePath + '/rzsc/flow/copy_flow_save.do',
            dataType: 'JSON',
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    layer.close(index);
                    dggui.dialog.succeed('操作成功！');
                    //刷新列表
                    reloadTable($('#flowNode'),"reloadFalse");
                    /*search($('#flowNode'));*/
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('保存失败，请联系管理员！！');
            }
        })
    }
</script>
